<?php
/**
 * Created by PhpStorm.
 * User: xuke
 * Date: 16/6/7
 * Time: 下午4:11
 */
namespace App\Http\Model;

class AccessToken extends Base
{
    protected $primaryKey = 'id';
    protected $table = 'access_token';
    public $timestamps = false;

    protected $guarded = [
        'id'
    ];

    public function setToken()
    {
        $token = md5(time().str_random(32));
        $this->access_token = $token;
        return $this;
    }

    public function setDevice($uuid)
    {
        $this->uuid = $uuid;
        return $this;
    }

    public function device()
    {
        return $this->hasOne(Device::class, 'uuid', 'uuid');
    }

    public function setLogin()
    {
        $this->login = 1;
        return $this;
    }

    public function logout()
    {
        $this->login = 2;
        return $this;
    }

    public function user()
    {
        return $this->hasOne(Users::class,'access_token', 'access_token');
    }
}